/*     */ package com.hp.bon.logreverse.bi;
/*     */ 
/*     */ /*     */ import java.sql.Timestamp;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Set;

/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;

import com.hp.bon.logreverse.BaseMsgProcess;
/*     */ import com.hp.bon.logreverse.ExtractBuzInfoService;
/*     */ import com.hp.bon.logreverse.LogFileRead;
/*     */ import com.hp.bon.logreverse.MsgInfo;
/*     */ import com.hp.bon.logreverse.ReverseLogEvent;
/*     */ import com.hp.bon.logreverse.buzBeans.BuzReadLog;
/*     */ import com.hp.bon.sgw.bean.XmlMessage;
/*     */ import com.hp.ocs.diameter.message.AVP;
/*     */ import com.hp.ocs.diameter.message.AVP_UTF8String;
/*     */ import com.hp.ocs.diameter.message.Message;
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BIMsgProcess extends BaseMsgProcess
/*     */ {
/*  28 */   private HashMap<String, BICallParam> pendingCallMap = new HashMap<String, BICallParam>();
/*  29 */   private static final Logger LOG = LoggerFactory.getLogger(BIMsgProcess.class);
/*  30 */   private long lastProcessTime = 0L;
/*     */   private int unused;
/*  32 */   private boolean isRecoveredFile = false;
/*     */   private ExtractBuzInfoService extractBuzInfoService;
/*  38 */   private List<String> Result_List = new ArrayList<String>();
/*  39 */   private Set<String> Result_Table_Set = new HashSet<String>();
/*     */ 
/*     */   public void setRecoveredFile(boolean isRecoveredFile)
/*     */   {
/*  34 */     this.isRecoveredFile = isRecoveredFile;
/*     */   }
/*     */ 
/*     */   @Autowired
/*     */   public void setExtractBuzInfoService(ExtractBuzInfoService extractBuzInfoService)
/*     */   {
/*  43 */     this.extractBuzInfoService = extractBuzInfoService;
/*     */   }
/*     */ 
/*     */   public void beginFileTrigger(LogFileRead logFileRead)
/*     */   {
/*  48 */     super.beginFileTrigger(logFileRead);
/*  49 */     this.unused = 0;
/*  50 */     this.Result_List.clear();
/*  51 */     this.Result_Table_Set.clear();
/*     */   }
/*     */ 
/*     */   public boolean processMsg(MsgInfo msgInfo)
/*     */   {
/*  56 */     this.lastProcessTime = msgInfo.getLogDate().getTime();
/*  57 */     if ((msgInfo.getMsg() instanceof Message))
/*  58 */       matchRequestAndAnswer((Message)msgInfo.getMsg(), msgInfo.getNodeName(), msgInfo.getLogEvent());
/*     */     else {
/*  60 */       matchRequestAndAnswer((XmlMessage)msgInfo.getMsg(), msgInfo.getLogEvent());
/*     */     }
/*  62 */     return true;
/*     */   }
/*     */ 
/*     */   public void endFileTrigger(LogFileRead logFileRead)
/*     */   {
/*  68 */     long timeOutTime = this.lastProcessTime - 100000L;
/*  69 */     ArrayList<String> timeoutSessionList = new ArrayList<String>();
/*  70 */     for (BICallParam pendingCall : this.pendingCallMap.values()) {
/*  71 */       if (pendingCall.getRequestTime() < timeOutTime)
/*     */       {
/*  73 */         timeoutSessionList.add(pendingCall.getSessionId());
/*     */       }
/*     */     }
/*  76 */     int timeoutNum = 0;
/*  77 */     for (String s : timeoutSessionList) {
/*  78 */       BICallParam rm = (BICallParam)this.pendingCallMap.remove(s);
/*  79 */       LOG.debug("drop timeout pending request:" + s);
/*  80 */       timeoutNum++;
/*     */ 
/*  82 */       if (!this.isRecoveredFile)
/*  83 */         extractMsg(rm);
/*     */     }
/*  85 */     if (!this.isRecoveredFile) {
/*  86 */       BuzReadLog lf = new BuzReadLog();
/*  87 */       lf.setFileName(logFileRead.getFileName());
/*  88 */       lf.setDbTime(new Timestamp(System.currentTimeMillis()));
/*  89 */       lf.setSuccessNum(logFileRead.getSuccessNum());
/*  90 */       lf.setFailedNum(logFileRead.getExceptionNum());
/*  91 */       this.extractBuzInfoService.createDB(this.Result_Table_Set);
/*  92 */       this.extractBuzInfoService.saveDB(lf, this.Result_List);
/*     */     }
/*  94 */     LOG.debug("[" + logFileRead.getFileName() + "] timeout:" + timeoutNum + ",unused:" + this.unused);
/*  95 */     super.endFileTrigger(logFileRead);
/*     */   }
/*     */ 
/*     */   private void matchRequestAndAnswer(XmlMessage msg, ReverseLogEvent logEvent) {
/*  99 */     if (msg.isRequest) {
/* 100 */       BICallParam callParam = new BICallParam(msg, msg.getMID(), msg.getSCID(), msg.getUID(), Integer.valueOf(logEvent.getLineSeq()), logEvent.getFileName());
/* 101 */       this.pendingCallMap.put(msg.getMID(), callParam);
/*     */     } else {
/* 103 */       BICallParam callParam = (BICallParam)this.pendingCallMap.remove(msg.getMID());
/* 104 */       if (callParam == null)
/*     */       {
/* 106 */         LOG.debug("drop unused soap answer:" + msg.getMID());
/* 107 */         this.unused += 1;
/* 108 */         return;
/*     */       }
/* 110 */       callParam.setAnswer(msg);
/*     */ 
/* 112 */       if (!this.isRecoveredFile)
/* 113 */         extractMsg(callParam);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void matchRequestAndAnswer(Message msg, String nodeName, ReverseLogEvent logEvent)
/*     */   {
/* 120 */     if (msg.header().isRequest()) {
/* 121 */       Message request = msg;
/* 122 */       AVP sessionIDAVP = request.find(263);
/* 123 */       String sessionID = AVP_UTF8String.queryValue(sessionIDAVP);
/* 124 */       AVP srvCtxAVP = request.find(461);
/* 125 */       String serviceContextId = AVP_UTF8String.queryValue(srvCtxAVP);
/* 126 */       BICallParam callParam = new BICallParam(request, sessionID, serviceContextId, nodeName, Integer.valueOf(logEvent.getLineSeq()), logEvent.getFileName());
/* 127 */       this.pendingCallMap.put(sessionID, callParam);
/*     */     } else {
/* 129 */       Message answer = msg;
/* 130 */       AVP sessionIDAVP = answer.find(263);
/* 131 */       String sessionID = AVP_UTF8String.queryValue(sessionIDAVP);
/* 132 */       BICallParam callParam = (BICallParam)this.pendingCallMap.remove(sessionID);
/* 133 */       if (callParam == null)
/*     */       {
/* 135 */         LOG.debug("drop unused dcc answer:" + sessionID);
/* 136 */         this.unused += 1;
/* 137 */         return;
/*     */       }
/* 139 */       callParam.setAnswer(answer);
/*     */ 
/* 141 */       if (!this.isRecoveredFile)
/* 142 */         extractMsg(callParam);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void extractMsg(BICallParam callParam)
/*     */   {
/* 153 */     List<String> list = this.extractBuzInfoService.extractMsg(callParam);
/*     */ 
/* 158 */     if ((list != null) && (list.size() == 2))
/*     */     {
/* 160 */       String tableName = (String)list.get(0);
/* 161 */       String sql = (String)list.get(1);
/* 162 */       if (sql != null) {
/* 163 */         this.Result_List.add(sql);
/* 164 */         this.Result_Table_Set.add(tableName);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public String getRecoveredFileName() {
/* 170 */     BuzReadLog readLog = this.extractBuzInfoService.getLastFile();
/* 171 */     if (readLog == null)
/*     */     {
/* 173 */       return null;
/*     */     }
/*     */ 
/* 177 */     return readLog.getFileName();
/*     */   }
/*     */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.logreverse.bi.BIMsgProcess
 * JD-Core Version:    0.6.1
 */